package com.dao.base;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.List;

import com.myHibernateDao.MyHibernateDaoSupport;


@SuppressWarnings("unchecked")
public abstract class EntityDao<T, PK extends Serializable> extends MyHibernateDaoSupport implements BaseDao<T, PK> {

	Class<T> clazz;
	
	public EntityDao() {
		clazz = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
	}
	
	public T get(PK id) {
		return super.getHibernateTemplate().get(clazz, id);
	}

	public List<T> find(String query) {
		return super.getHibernateTemplate().find(query);
	}
	
	public List<T> find(String query, Object... params) {
		return super.getHibernateTemplate().find(query, params);
	}

	public void save(T e) {
		super.getHibernateTemplate().save(e);
	}
	
	public void update(T e) {
		super.getHibernateTemplate().update(e);
	}

	public void delete(PK id) {
		delete(get(id));
	}
	
	public void delete(T e) {
		super.getHibernateTemplate().delete(e);
	}

}
